package 力扣日常刷题.木22二月.第13天219;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author 帅小伙
 * @date 2022/2/19
 * @description
 */
public class Demo105LRU  {

    class LRUCache extends LinkedHashMap<Integer,Integer>{

        private int capacity;
        public LRUCache(int capacity) {
            super(capacity,0.75F,true);
            this.capacity = capacity;
        }

        public int get(int key) {
            return super.getOrDefault(key,-1);
        }

        public void put(int key, int value) {
            super.put(key,value);
        }

        @Override
        protected boolean removeEldestEntry(Map.Entry<Integer, Integer> eldest) {
            return size() > capacity;
        }
    }

}
